var app = getApp();
var api = require('../../../config/api.js');
var util = require('../../../utils/util.js');


Page({
  data: {
    price: 0,
    pay_type:1,
    selected: 1
  },
  onLoad: function(a) {},
  onReady: function() {},
  onShow: function() {
    var c = this;
    util.request(api.getPrice).then(function(res) {
      console.log(res);
      if (res.errno == 0) {
        c.setData({
          price: res.data.avaibleAmount ? res.data.avaibleAmount:0
        });
      } else {
        wx.showModal({
          title: '注意',
          content: '服务器出小差了，请稍候重试.',
          showCancel: false
        });
      }
    })
  },
  onPullDownRefresh: function() {},
  select: function (a) {
    var e = a.currentTarget.dataset.index;
    e != this.data.check && this.setData({
      name: "",
      mobile: "",
      bank_name: ""
    }), this.setData({
      selected: e
    });
  },
  formSubmit: function(a) {
    var e = this,
      t = parseFloat(parseFloat(a.detail.value.cash).toFixed(2)),
      i = e.data.price;
      var n = e.data.selected;
        if (0 == n || 1 == n || 2 == n) {
          if (!a.detail.value.name || null == a.detail.value.name) return void wx.showToast({
            title: "姓名不能为空",
            image: "/images/icon-warning.png"
          });
          if (!a.detail.value.mobile || null == a.detail.value.mobile) return void wx.showToast({
            title: "账号不能为空",
            image: "/images/icon-warning.png"
          });
        }
        if (!t || null == t){
          return void wx.showToast({
            title: "请输入提现金额",
            image: "/images/icon-warning.png"
          });
        }




    if (i < t) {
      wx.showModal({
        title: '注意',
        content: '提现金额不能超过 '+i+' 元',
        showCancel: false
      });
    } else if (t < parseFloat(1)) {
      wx.showModal({
        title: '注意',
        content: "提现金额不能低于 1.00 元",
        showCancel: false
      });
    } else {
      wx.showLoading({
        title: "正在提交",
        mask: !0
      });
      util.request(api.cash, {
        cash: t,
        mobile: a.detail.value.mobile,
        name: a.detail.value.name,
        type:n
      }, 'post').then(function(res) {
        wx.hideLoading(), wx.showModal({
          title: "提示",
          content: res.errmsg,
          showCancel: !1,
          success: function (a) {
            a.confirm && wx.navigateBack({});
          }
        });
        
        }).catch(res => {
        wx.hideLoading();
        wx.showModal({
          title: "提示",
          content: "提现失败,请稍候重试",
          showCancel: !1,
        });
      });
    }
  }
   
});